import { defineStore } from 'pinia'
import request from '@/utils/request'
import { UserInfoType, ApiRes } from '@/types/data'
export default defineStore('user', {
  state () {
    return {
      userInfo: {} as UserInfoType
    }
  },
  actions: {
    async loginSocial (unionId: string) {
      const res = await request.request({
        url: '/login/social',
        method: 'post',
        data: {
          unionId,
          source: 6
        }
      })
      // 如果登陆成功，直接保存用户信息
      this.userInfo = res.data.result
      console.log(res)
    },
    // 帐号绑定
    async loginSocialBind (unionId: string, mobile: string) {
      const res = await request.request<ApiRes<UserInfoType>>({
        url: '/login/social/bind',
        method: 'post',
        data: {
          unionId,
          mobile,
          code: '123456'
        }
      })
      this.userInfo = res.data.result
      console.log('绑定的返回值', res)
    }
  }
})
